<?php
/**
 * 活动表
 * Date: 2021年3月4日
 * Time: 18:06:03
 */

namespace App\Model\BbcModel;

use Service\Code\Normal;
use App\Model\BaseModel\BaseBbcModel;

class ActivityDiscount extends BaseBbcModel {

    public $table = 'ly_activity_discount';

    /**
     * 获取活动详情描述
     */
    public static function getContent($param) {
        if (!$param['activity_id']) {
            return Normal::returnCode(Normal::FAIL, 'invalid argument activity_id');
        }
        $list = self::where('activity_id', $param['activity_id'])->get()->toArray();
        if (empty($list)) {
            return Normal::returnCode(Normal::FAIL, '活动详情不存在');
        }
        $content = '';
        foreach ($list as $v) {
            $unit     = Activity::$unit[$v['unit_type']];
            $discount = round($v['discount'] / 10, 1);
            if ($v['unit_type'] == 0) {
                $content .= '满' . round($v['full'], 2) . '打' . $discount . '折,';
            } else {
                $content .= '满' . round($v['full'], 2) . $unit . '打' . $discount . '折,';
            }
        }
        $content = rtrim($content, ',');
        return Normal::returnCode(Normal::SUC, '获取成功', ['list' => $list, 'content' => $content]);
    }
}